<?php 
    session_start();
	include ("../core/conn.php");
	global $db;	
	$db = get_conn();
	

		$sql = "select i.id_invoice, i.amount, i.due_date, i.exp_date, i.description, l.number, l.id_location
						from `invoices` i , `locations` l where i.istatus='W' and i.id_location = l.id_location order by i.id_invoice";
			
		$result = mysql_query($sql);
		if($result){
			$data ="<table width='80%' align='left' >";
			if(mysql_num_rows($result) > 0){
					$data .="<tr>
						<td align='left' >
							&nbsp;
						</td>
						<td align='left' >
							ID
						</td>
						<td align='left' >
							Filial
						</td>							
						<td align='left' >
							Fecha Cobro
						</td>
						<td align='left' >
							Monto
						</td>	
						<td align='left' >
							Opciones
						</td>																								
						</tr>";					
				while($row = mysql_fetch_array($result)){
					$controls = "<a onClick='$(this).modal({width:350, height:350}).open(); return false;' href='invoices_edit.php?id=".$row['id_invoice']."'>Editar / Comentarios</a>";	
					$data .="
					    <tr>
						<td><input type='checkbox' name='id_invoice[]' value='".$row['id_invoice']."' id='r_".$row['id_invoice']."' ></td>
						<td align='left' >
							".$row['id_invoice']."
						</td>
						<td align='left' >
							".$row['number']." 
						</td>							
						<td align='left' >
							".format_date($row['due_date'])."
						</td>
						<td align='left' >
							".format_date($row['exp_date'])."
						</td>
						<td align='left' >
							".format($row['amount'],2)."
						</td>	
						<td align='left' >
							".$controls."
						</td>																								
						</tr>";
				}//while
			}//if
			else{
				$btn_disabled = true;
				$data .= "<tr><td align='center'>No hay cobros por terminar</td></tr>";			
			}
			$data .="</table>";
		}else{
			error_handling($sql,mysql_error());
		}

	echo $data;
?>